﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Legend.Guarding
{
    /// <summary>
    /// A helper class used by the Ensure-class
    /// to provide a fluent interface for guarding.
    /// </summary>
    /// <typeparam name="T">The type of argument this info
    /// object represents.</typeparam>
    public class ArgumentInfo<T>
        : IArgumentInfo<T>
    {
        /// <summary>
        /// The value of the argument.
        /// </summary>
        private readonly T valueField;

        /// <summary>
        /// The name of the argument in the calling methods
        /// argument list.
        /// </summary>
        private string argumentNameField;

        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="value">The value of the argument.</param>
        public ArgumentInfo(T value)
        {
            this.valueField = value;    
        }

        /// <summary>
        /// Sets the name of the argument in the calling methods
        /// argument list.
        /// </summary>
        /// <param name="argumentName">The name of the argument in the calling methods
        /// argument list.</param>
        /// <returns>The same ArgumentInfo(T)-instance.</returns>
        public ArgumentInfo<T> Named(string argumentName)
        {
            this.argumentNameField = argumentName;
            return this;
        }

        ArgumentInfo<T> IArgumentInfoAccessor<T>.And
        {
            get { return this; }
        }

        T IArgumentInfo<T>.Value
        {
            get
            {
                return this.valueField;
            }
        }

        string IArgumentInfo<T>.ArgumentName 
        {
            get
            {
                return this.argumentNameField;
            }
        }
    }
}
